package com.woniuxy.third.service.impl;

import com.woniuxy.third.entity.*;
import com.woniuxy.third.mapper.ChapterMapper;
import com.woniuxy.third.mapper.CourseMapper;
import com.woniuxy.third.mapper.SectionMapper;
import com.woniuxy.third.service.CourseService;
import com.woniuxy.third.service.OrderService;
import com.woniuxy.third.utils.GetUserUtil;
import org.springframework.context.annotation.ImportResource;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {
    @Resource
    private CourseMapper courseMapper;
    @Resource
    private ChapterMapper chapterMapper;
    @Resource
    private SectionMapper sectionMapper;
    @Resource
    private OrderService orderService;

    @Override
    public Course findCourseByid(int id) {
        return courseMapper.findCourseByid(id);
    }

    @Override
    public List<Course> findAllCourse() {
        return courseMapper.findAllCourse();
    }

    @Override
    public boolean addCourse(Course course) {
        return courseMapper.addCourse(course);
    }



    @Override
    public List<Chapter> findChaptersByCourseId(int id) {
        List<Chapter> chapters = chapterMapper.findChaptersByCourseid(id);
        for (Chapter chapter:chapters) {
            List<Section> sections = sectionMapper.findSectionsByChaptid(chapter.getId());
            chapter.setSections(sections);
        }
        return chapters;
    }

    @Override
    public List<Course> findCourseByUid(int uid) {
       List<Course> courses = courseMapper.findCourseByUid(uid);
       return courses;
    }

    @Override
    public int updateCourse(Course course) {
        return courseMapper.updateCourse(course);
    }

    public List<Course> findCollectionCourseByUid(int uid){
        List<Course> collectionCourses = courseMapper.findCollectionCourseByUid(uid);
        return collectionCourses;
    }

    @Override
    public List<Course> findCourseBytid(int id) {
        return courseMapper.findCourseBytid(id);
    }

    @Override
    public Course findCourseByName(String name,int id) {
        return courseMapper.findCourseByName(name,id);
    }
}
